Imports System.Text.RegularExpressions

Public Class BLRegex

    Public iFormat As eFormat

    Public Enum eFormat
        eType = 0
        eURL = 1
        eEmail = 2

        eHTML = 10
        eCSV = 11

        eWinDrive = 20
        eWinFolder = 21
        eWinFile = 22
    End Enum

    Public Function RegexValidator(ByVal eFormat As eFormat, ByVal sTextToValidate As String) As Boolean

        'Return True
        Dim sPattern As String = ""

        Select Case eFormat
            Case BLRegex.eFormat.eType
                sPattern = ""
            Case BLRegex.eFormat.eURL
                sPattern = "http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?"
            Case BLRegex.eFormat.eEmail
                sPattern = "\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}\b"
                'sPattern = "\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"

            Case BLRegex.eFormat.eHTML
                sPattern = "<html>.*?<head>.*?<title>.*?</title>.*?</head>.*?<body[^>]*>.*?</body>.*?</html>"
            Case BLRegex.eFormat.eCSV
                sPattern = ""

            Case BLRegex.eFormat.eWinDrive
                sPattern = "\b[a-z]:\\"
            Case BLRegex.eFormat.eWinFolder
                sPattern = "(?:[^\\/:*?""<>|\r\n]+\\)*"
            Case BLRegex.eFormat.eWinFile
                sPattern = "[^\\/:*?""<>|\r\n]*"
        End Select

        Dim m As Match = Regex.Match(sTextToValidate, sPattern, RegexOptions.IgnoreCase)
        If m.Success Then Return True Else Return False

    End Function
End Class
